
package com.cn.ycy.interceptor;


import com.google.common.collect.Lists;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Date;
import java.util.concurrent.TimeUnit;

@Slf4j
public class SecurityInterceptor extends HandlerInterceptorAdapter {

    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
        log.warn("preHandle -> {} {}  {}", request.getServletPath(),request, response);
        if (request.getMethod().equalsIgnoreCase(HttpMethod.OPTIONS.name())) {
            return true;
        }
        Integer responseCode = Integer.valueOf(HttpStatus.FORBIDDEN.value());
        boolean exists = false;
        String auth = request.getHeader("auth");
        if (StringUtils.isNotBlank(auth)) {
            return false;
        }
        return true;
    }


    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
        log.warn("afterCompletion -> {} {}  {}", request.getServletPath(),request, response);
    }

    public void afterConcurrentHandlingStarted(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        log.warn("afterConcurrentHandlingStarted -> {} {}  {}", request.getServletPath(),request, response);
    }


}

